package com.asnike.navi{
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	public class StepNavigation extends Sprite{
		
		public var btnStep0:StepButton;
		public var btnStep1:StepButton;
		public var btnStep2:StepButton;
		public var btnStep3:StepButton;
		public var btnStep4:StepButton;
		public var btnStep5:StepButton;
		public var selectionStep0:StepSelection;
		public var selectionStep1:StepSelection;
		public var selectionStep2:StepSelection;
		
		
		private var _btnClickCallback:Function;
		
		public function StepNavigation(){
			super();
			btnStep0.setStateActivation();
			initEvent();
			initSelections();
		}
		private function initEvent():void{
			btnStep0.addEventListener( MouseEvent.CLICK, click );
			btnStep1.addEventListener( MouseEvent.CLICK, click );
			btnStep2.addEventListener( MouseEvent.CLICK, click );
			btnStep3.addEventListener( MouseEvent.CLICK, click );
			btnStep4.addEventListener( MouseEvent.CLICK, click );
			btnStep5.addEventListener( MouseEvent.CLICK, click );
		}
		private function click( $e:MouseEvent ):void{
			if( _btnClickCallback is Function ){
				_btnClickCallback( int( $e.target.name.substr( -1 ) ) );
				selectButton( int( $e.target.name.substr( -1 ) ) );
			}
		}
		public function selectButton( $index:int ):void{
			var i:int, j:int, button:StepButton;
			
			for( i = 0, j = 6 ; i < j ; ++i ){
				button = this['btnStep' + i] as StepButton;
				if( button.isSelected() === false ){
					button.setStateInactivation();
				}
			}
			StepButton( this['btnStep' + $index] ).setStateActivation();
			if( getChildByName( 'selectionStep' + $index )  ){
				StepSelection( this['selectionStep' + $index] ).hide();
			}
		}
		private function initSelections():void{
			selectionStep0.hide();
			selectionStep1.hide();
			selectionStep2.hide();
		}
		
		public function setBtnClickCallback( $function:Function ):void{
			_btnClickCallback = $function;
		}
		
		public function setSelection( $step:int, $index:int ):void{
			StepButton( this['btnStep' + $step] ).setStateSelection();
			StepSelection( this['selectionStep' + $step] ).select( $index );
			StepSelection( this['selectionStep' + $step] ).show();
		}
	}
}